﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuildPlannerLib.Buildings;
using BuildPlannerLib.Enums;
using BuildPlannerLib.Terran.Buildings;
using BuildPlannerLib.Terran.Enums;

namespace BuildPlannerLib.Terran
{
    // Class for Terran-specific fields
    public class TerranPlayer : Player
    {
        // Integer field for Nukes and idle addons
        public int Nuke;
        private int idleReactor;
        private int idleTechLab;
        public int IdleReactor
        {
            get { return idleReactor; }
            set { idleReactor = value; }
        }
        public int IdleTechLab
        {
            get { return idleTechLab; }
            set { idleTechLab = value; }
        }

        // Constructor with a parameter for build
        public TerranPlayer(Build build) : base()
        {
            SupplyMaximum = new ResourceWithMaximum(11, 200);
            SupplyInProduction = 11;

            MainBuilding = new CommandCenter();

            Buildings.Add(new NonProduction("Refinery", 75, 0, 3000, 0));
            Buildings.Add(new SupplyDepot());
            Buildings.Add(new ProductionBuilding("Engineering Bay", 125, 0, 3500));
            Buildings.Add(new AddonBuilding("Barracks", 150, 0, 6500, "Supply Depot"));
            Buildings.Add(new NonProduction("Missile Turret", 100, 0, 2500, "Engineering Bay"));
            Buildings.Add(new NonProduction("Sensor Tower", 125, 100, 2500, "Engineering Bay"));
            Buildings.Add(new NonProduction("Bunker", 100, 0, 4000, "Barracks"));
            Buildings.Add(new AddonBuilding("Factory", 150, 100, 6000, "Barracks"));
            Buildings.Add(new GhostAcademy());
            Buildings.Add(new ProductionBuilding("Armory", 150, 100, 6500, "Factory"));
            Buildings.Add(new AddonBuilding("Starport", 150, 100, 5000, "Factory"));
            Buildings.Add(new ProductionBuilding("Fusion Core", 150, 150, 6500, "Starport"));
            
            Units.Add(new TerranUnit("Marine", 50, 0, 1, 2500, "Barracks", false));
            Units.Add(new TerranUnit("Reaper", 50, 50, 1, 4500, "Barracks", (build.Expansion == Expansion.WingsOfLiberty)));
            Units.Add(new TerranUnit("Marauder", 125, 50, 2, 3000, "Barracks", true));
            Units.Add(new TerranUnit("Ghost", 200, 100, 2, 4000, "Barracks", true, "Ghost Academy"));

            Units.Add(new TerranUnit("Hellion", 100, 0, 2, 3000, "Factory", false));
            if (build.Expansion != Expansion.WingsOfLiberty)
                Units.Add(new TerranUnit("Widow Mine", 75, 25, 2, 4000, "Factory", false));
            Units.Add(new TerranUnit("Siege Tank", 150, 125, 3, 4500, "Factory", true));
            if (build.Expansion != Expansion.WingsOfLiberty)
                Units.Add(new TerranUnit("Hellbat", 100, 0, 2, 3000, "Factory", false, "Armory"));
            Units.Add(new TerranUnit("Thor", 300, 200, 6, 6000, "Factory", true, "Armory"));

            Units.Add(new TerranUnit("Medivac", 100, 100, 2, 4200, "Starport", false));
            Units.Add(new TerranUnit("Viking", 150, 75, 2, 4200, "Starport", false));
            Units.Add(new TerranUnit("Banshee", 150, 100, 3, 6000, "Starport", true));
            Units.Add(new TerranUnit("Raven", 100, 200, 2, 6000, "Starport", true));
            Units.Add(new TerranUnit("Battlecruiser", 400, 300, 6, 9000, "Starport", true, "Fusion Core"));

            Upgrades.Add(new Upgrade("Building Armor", 150, 150, 14000, "Engineering Bay"));
            Upgrades.Add(new Upgrade("Hi-Sec Auto Tracking", 100, 100, 8000, "Engineering Bay"));
            Upgrades.Add(new Upgrade("Neosteel Frame", 100, 100, 11000, "Engineering Bay"));

            Upgrades.Add(new Upgrade("Combat Shield", 100, 100, 11000, "Barracks"));
            Upgrades.Add(new Upgrade("Concussive Shells", 50, 50, 6000, "Barracks"));
            Upgrades.Add(new Upgrade("Stimpack", 100, 100, 17000, "Barracks"));
            if (build.Expansion == Expansion.WingsOfLiberty)
                Upgrades.Add(new Upgrade("Nitro Packs", 50, 50, 10000, "Barracks", "Factory"));

            Upgrades.Add(new Upgrade("Moebius Reactor", 100, 100, 8000, "Ghost Academy"));
            Upgrades.Add(new Upgrade("Personal Cloaking", 150, 150, 12000, "Ghost Academy"));

            if (build.Expansion != Expansion.WingsOfLiberty)
                Upgrades.Add(new Upgrade("Drilling Claws", 150, 150, 11000, "Factory"));
            Upgrades.Add(new Upgrade("Infernal Pre-igniter", 150, 150, 11000, "Factory"));
            if (build.Expansion == Expansion.WingsOfLiberty)
                Upgrades.Add(new Upgrade("Siege Tech", 100, 100, 8000, "Factory"));
            if (build.Expansion != Expansion.WingsOfLiberty)
                Upgrades.Add(new Upgrade("Transformation Servos", 150, 150, 11000, "Factory", "Armory"));
            if (build.Expansion == Expansion.WingsOfLiberty)
                Upgrades.Add(new Upgrade("250mm Strike Cannon", 150, 150, 11000, "Factory"));

            Upgrades.Add(new Upgrade("Caduceus Reactor", 100, 100, 8000, "Starport"));
            Upgrades.Add(new Upgrade("Cloaking Field", 100, 100, 11000, "Starport"));
            Upgrades.Add(new Upgrade("Corvid Reactor", 150, 150, 11000, "Starport"));
            Upgrades.Add(new Upgrade("Durable Materials", 150, 150, 11000, "Starport"));

            Upgrades.Add(new Upgrade("Behemoth Reactor", 150, 150, 8000, "Fusion Core"));
            Upgrades.Add(new Upgrade("Weapon Refit", 150, 150, 6000, "Fusion Core"));

            string[] requirement = new string[3] { null, "Armory", "Armory" };
            LevelUpgrades.Add(new LevelUpgrade("Infantry Weapons", 100, 75, 100, 75, 16000, 3000, "EngineeringBay", requirement));
            LevelUpgrades.Add(new LevelUpgrade("Infantry Armor", 100, 75, 100, 75, 16000, 3000, "EngineeringBay", requirement));
            LevelUpgrades.Add(new LevelUpgrade("Vehicle Weapons", 100, 75, 100, 75, 16000, 3000, "Armory"));
            if (build.Expansion == Expansion.WingsOfLiberty)
            {
                LevelUpgrades.Add(new LevelUpgrade("Vehicle Plating", 100, 75, 100, 75, 16000, 3000, "Armory"));
                LevelUpgrades.Add(new LevelUpgrade("Ship Weapons", 100, 75, 100, 75, 16000, 3000, "Armory"));
                LevelUpgrades.Add(new LevelUpgrade("Ship Plating", 150, 75, 150, 75, 16000, 3000, "Armory"));
            }
            else
            {
                LevelUpgrades.Add(new LevelUpgrade("Vehicle and Ship Plating", 100, 75, 100, 75, 16000, 3000, "Armory"));
                LevelUpgrades.Add(new LevelUpgrade("Ship Weapons", 100, 75, 100, 75, 16000, 3000, "Armory"));
            }
        }

        // Sets all fields to the state at the start of simulation
        public override void Reset()
        {
            base.Reset();

            SupplyMaximum.Set(11);
            SupplyInProduction = 11;
            
            Nuke = 0;
        }
    }
}
